package pl.edu.mimuw.irs.rcp.persistence;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;


public class SerializablePersistence<T> extends AbstractPersistence<T> {

	// *** Attributes

	// *** Methods

	@SuppressWarnings("unchecked")
	public T loadFromStream(InputStream stream) throws IOException, ClassNotFoundException {
		T object = null;
		ObjectInputStream objectStream = null;
		
		objectStream = new ObjectInputStream(stream);
		object = (T)objectStream.readObject();
		objectStream.close();
		
		return object;
	}

	public void writeToStream(T object, OutputStream stream) throws IOException {
		
		ObjectOutputStream objectStream = null;
		
		objectStream = new ObjectOutputStream(stream);
		objectStream.writeObject(object);
		objectStream.close();
		
	}
}
